import request from '@/utils/request'

//登录
export function login (data) {
  return request({
    url: '/userLogin',
    method: 'post',
    params: {
      uname: data.uname,
      upassword: data.upassword,
    }
  })
}

//注册
export function register (data) {
  return request({
    url: '/UserRegister',
    method: 'post',
    data
  })
}

//加载收藏列表
export function onLoadCollect (data) {
  return request({
    url: '/SelectGoodsByUser',
    method: 'post',
    params: {
      uId: data.uId
    }
  })
}
//取消收藏
export function deleteCollect (data) {
  return request({
    url: '/deleteCollect',
    method: 'post',
    data
  })
}
//根据用户id和商品id收藏商品
export function selectGood (data) {
  return request({
    url: 'collectById',
    method:'post',
    data
  })
}
//判断某商品是否被收藏
export function checkSelect (data) {
  return request({
    url: '/selectById',
    method: 'post',
    data
  })
}

//获取用户全部订单
export function getAllOrders (data) {
  return request({
    url: '/getOrdersAllUser',
    method: 'post',
    params:{
      uid: data.uid,
    }
  })
}
//获取用户的全部地址
export function getAllAddress (data) {
  return request({
    url:'/getFindAll',
    method: 'post',
    params:{
      uId: data.uid,
    }
  })
}
//根据aid删除地址
export function deleteAddress (data) {
  return request({
    url:'/deleteAddress',
    method:'post',
    params:{
      aId:data.aid,
    }
  })
}
//根据aid修改地址
export function editAddress (data) {
  return request({
    url: '/modifUpdateAddress',
    method: 'post',
    params:{
      aId: data.aid,
      rName: data.name,
      rPhone:data.phone,
      rAddress:data.address,
    }
  })
}
//用户新增收货地址
export function addAddress (data) {
  return request({
    url:'/addAddress',
    method: 'post',
    data
  })
}

//获取用户全部订单
export function findOrdersAllUserencapsulation (data) {
  return request({
    url: "/findOrdersAllUser2",
    method: "post",
    params: {
      // uid: 1,
      uid: data.uid, //从本地store中获取uid
    },
  })
}

//根据商品名模糊搜索
export function findOrderByMNameUserencapsulation (data) {
  return request({
    url: "/findOrderByNameUser2",
    method: "post",
    params: {
      uid: data.uid,
      gName: data.gName,
    },
  })
}

//导航栏根据状态查询
export function stateNavigationencapsulation (data) {
  return request({
    url: "/findOrderByStateUser2",
    method: "post",
    params: {
      uid: data.uid,
      oState: data.oState,
    },
  })
}

// 删除订单
export function deleteOrderUserencapsulation (data) {
  return request({
    url: "/deleteOrderByOrderNumber",
    method: "post",
    params: {
      orderNumber:data.orderNumber
    },
  })
}
// 确认收货
export function ButtonByoState2encapsulation (data) {
  return request({
    url: "/ChangeStateUser",
    method: "post",
    params: {
      uid: data.uid,
      orderNumber: data.orderNumber,
      orderstate: data.orderstate,
    },
  })
}
//查询用户的默认地址
export  function findDefaultAddress (data) {
  return request({
    url: '/findDefaultAddress',
    method: 'post',
    params:{
      uid: data.uid,
    }
  })
}
//点击购买生成订单
export function creatNewOrder (data) {
  return request({
    url: '/createNewOrders2',
    method: 'post',
    params:{
      uid: data.uid,
      gid: data.gid,
      mid: data.mid,
      oName: data.oName,
      oPhone: data.oPhone,
      oAddress: data.oAddress,
    }
  })
}
//订单详情
export function selectOrderDetail (data) {
  return request({
    url: '/findOrderByOrderNumberUser2',
    method: 'post',
    params:{
      orderNumber: data.orderNumber,
      uid: data.uid,
    }
  })
}
//查询商家名
export  function findMerchantName (data) {
  return request({
    url: '/findMerchantName',
    method: 'post',
    params:{
      mid:parseInt(data.mid),
    }
  })
}
//查询最新生成的订单号
export function findNewstOrder (data) {
  return request({
    url: '/findNewstOrder',
    method:'post',
    params:{
      uid:parseInt(data.uid),
    }
  })
}
//查询全部商品
export function selectAllGoods (data) {
  return request({
    url: '/selectTotalGoods',
    method: 'post',
    params:{
      gName: data.gName,
      currentPage:data.currentPage, //当前页码
      currentCount:data.currentCount, //一页显示的个数
    }
  })
}
//查询商家全部商品
export function selectMerchantAllGoods (data) {
  return request({
    url: '/selectAllGoods',
    method: 'post',
    params:{
      mId: data.mid,
      gName: '',
    }
  })
}
//查询5条商品的图片
export function selectImgs () {
  return request({
    url: '/selectImgs',
    method:'get',
  })
}
//查询全部的在架的商品的数量
export function selectTotalGoodsCount (data) {
  return request({
    url: '/selectTotalGoodsCount',
    method: 'get',
    params:{
      gName:data.gName,
    }
  })
}
